﻿using dreamwork.mobile.app.api.Models.Data;
using Microsoft.Extensions.Configuration;
using MongoDB.Driver;
using System.Security.Authentication;

namespace dreamwork.mobile.app.api.Infrastructure
{
    public class MongodbContext : IMongodbContext
    {
        private readonly IMongoDatabase _db;
        public MongodbContext(IConfiguration config)
        {
            string connectionString = config["MongoDB:ConnectionString"];
            MongoClientSettings settings = MongoClientSettings.FromUrl(
              new MongoUrl(connectionString)
            );
            //settings.SslSettings =
            //  new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 };
            var mongoClient = new MongoClient(settings);
            if (mongoClient != null)
                _db = mongoClient.GetDatabase(config["MongoDB:Database"]); 
        }
        public IMongoCollection<NormalUser> NormalUsers => _db.GetCollection<NormalUser>("NormalUser");
        public IMongoCollection<TerminalUser> TerminalUsers => _db.GetCollection<TerminalUser>("TerminalUser");
    }
}
